package com.promis.party.ui.learneducation.office;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.promis.compat.StatusBarCompat;
import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.party.helper.UIHepler;
import com.promis.party.ui.home.message.MessageDetailActivity;
import com.promis.widget.paging.OnPageRefreshListener;
import com.promis.widget.paging.OnPageScrollListener;
import com.promis.widget.paging.PageRefreshRecyclerView;
import com.promis.widget.recycler.LinearSpacingItemDecoration;
import com.promis.widget.recycler.RecyclerLayoutManagerHelper;

/**
 * Created by zcy on 2018/9/25.
 */

public class LearnEducationActivity extends AppCompatActivity {

    private ContextHelper contextHelper;

    private SpeechAdapter speechAdapter;
    private LearnNineteenAdapter adapter;
    private PartyConstitutionAdapter partyConstitutionAdapter;
    private PageRefreshRecyclerView recyclerView;
    private TextView txtvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarCompat.translucentStatusBar(this);
        StatusBarCompat.blackTextStatusBar(this);
        setContentView(R.layout.activity_learn_education);
        UIHepler.goBack(LearnEducationActivity.this, R.id.activity_learn_education_imgv_back);

        recyclerView = findViewById(R.id.activity_learn_education_rcyv);
        txtvTitle = findViewById(R.id.activity_learn_education_txtv_title);

        initData();
        initListener();
    }

    private void initData() {
        contextHelper = new ContextHelper(getBaseContext());

        if(getIntent().hasExtra("nineteen")){
            txtvTitle.setText("学习十九大");
        }else if(getIntent().hasExtra("partyconstitution")){
            txtvTitle.setText("党章党规");
        }else if(getIntent().hasExtra("speech")){
            txtvTitle.setText("系列讲话");
        }

        RecyclerView recycler = recyclerView.getRecyclerView();
        RecyclerLayoutManagerHelper.buildVerticalLinearLayoutManager(getBaseContext(), recycler);
        recycler.addItemDecoration(new LinearSpacingItemDecoration(getBaseContext(), LinearLayoutManager.VERTICAL, 0, R.color.split_line));
        if(getIntent().hasExtra("nineteen")){
            adapter = new LearnNineteenAdapter(getBaseContext());
            recycler.setAdapter(adapter);
        }else if(getIntent().hasExtra("partyconstitution")){
            partyConstitutionAdapter = new PartyConstitutionAdapter(getBaseContext());
            recycler.setAdapter(partyConstitutionAdapter);
        }else if(getIntent().hasExtra("speech")){
            speechAdapter = new SpeechAdapter(getBaseContext());
            recycler.setAdapter(speechAdapter);
        }

    }

    private void initListener() {
        recyclerView.setOnPageScrollListener(new OnPageScrollListener() {
            @Override
            public void onLoadPageData() {
            }
        });

        recyclerView.setOnRefreshListener(new OnPageRefreshListener() {
            @Override
            public void onRefresh() {

            }
        });

        if(adapter != null) {
            adapter.setOnItemClickListener(new LearnNineteenAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    Intent intent = new Intent(getBaseContext(), MessageDetailActivity.class);
                    startActivity(intent);
                }
            });
        }

        if(partyConstitutionAdapter != null) {
            partyConstitutionAdapter.setOnItemClickListener(new PartyConstitutionAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    Intent intent = new Intent(getBaseContext(), MessageDetailActivity.class);
                    startActivity(intent);
                }
            });
        }

        if(speechAdapter != null) {
            speechAdapter.setOnItemClickListener(new SpeechAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    Intent intent = new Intent(getBaseContext(), MessageDetailActivity.class);
                    startActivity(intent);
                }
            });
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
//                case RequestCode.CITY : LetterSortActivity.Helper.onActivityResult(data, txtvCity); break;
//                case RequestCode.PETSELFISH :findOwnerPet(); break;
            }
        }
    }

//    public void httpFindDynamicList() {
//        HttpJsonParams params = new HttpJsonParams();
//        params.add("interest",1);
//        if (UserPreferences.getInstance(getContext()).exists()) {
//            params.add("userId", UserPreferences.getInstance(getContext()).getId());
//        }
//        String url = contextHelper.getServiceUrl(R.string.findInterestDynamicList);
//        new HttpClient<JsonList<Dynamic>>(getContext()) {
//            @Override
//            protected void onSuccess(JsonList<Dynamic> result) {
//                dynamicList = result.getDataList();
//                adptAdopt.notifyDataSetChanged(dynamicList);
//            }
//        }.postAsyn(url, params);
//    }
}